package com.tanhua.app.controller;

import com.tanhua.app.service.UserService;

import com.tanhua.domain.db.User;
import com.tanhua.domain.db.UserInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

@RestController
public class UserInfoController {
    @Autowired
    private UserService userService;

    @GetMapping(value = "/users", name = "查询用户信息")
    public ResponseEntity findUserInfoVo(Long userID, Long huanxinID, @RequestHeader("Authorization") String token) {
        if (userID != null) {
            //genju userID查询
            return userService.findUserInfoVo(userID);
        } else if (huanxinID != null) {
            //根据huanxinID 查询
            return userService.findUserInfoVo(huanxinID);
        } else {
            //根据token查询
            User user = userService.findUserByToken(token);
            return userService.findUserInfoVo(user.getId());
        }
    }
    //修改用户头像
    @PostMapping(value = "/users/header", name = "修改用户头像")
    public ResponseEntity updatePic(MultipartFile headphoto, @RequestHeader("Authorization") String token) throws Exception {
        return  userService.loginReginfoPic(headphoto,token);
    }
    //修改用户信息
    @PutMapping(value = "/users",name = "修改用户信息")
    public ResponseEntity updateUserInfo(@RequestBody UserInfo userInfo, @RequestHeader("Authorization") String token){
        return userService.updateUserInfo(userInfo,token);
    }
}